// 获取token
import { reqPhoneLogin,reqloginList } from "@/api"
const state = {
    token: localStorage.getItem('token') || '',
    loginmessage:JSON.parse(localStorage.getItem('loginmessage')) || {},
    getloginList:JSON.parse(localStorage.getItem('loginList')) || {},
    prtivatesum:localStorage.getItem('prtivatesum') || 0,
    isplaylist: 1, //改变状态
    isdisponone:1,//改变状态栏的属性
    isdispontow:1,//改变状态栏的属性
}
const mutations = {
    GETPHONELOGIN(state,data){
        state.token = data.token,
        state.loginmessage = data
    },
    GETLOGINLIST(state,data){
        state.getloginList = data
    },
    CHANGPRTIVSUM(state,data){
        state.prtivatesum = data
    },
    ISPLAYLIST(state,data){
        state.isplaylist = data
    },
    ISDISPON(state,data){
        console.log(data)
        state.isdisponone = data
    },
    ISDISPONTOW(state,data){
        console.log(data)
        state.isdispontow = data
    }
}
const actions ={
    // 登录
     async getPhoneLogin({commit},data){
        const result = await reqPhoneLogin(data)
        console.log(result)
        if(result.code == 200){
            commit('GETPHONELOGIN',result)
            localStorage.setItem('token',result.token)
            localStorage.setItem('loginmessage',JSON.stringify(result))
            return result.code
        }else{
            return Promise.reject(new Error('reject'))
        }
    },
    // 获取账号详细
    async getloginList({commit},uid){
        const result = await reqloginList(uid)
        // console.log(result)
        // console.log(result)
        if(result.code == 200){
            
            commit('GETLOGINLIST',result)
            localStorage.setItem('loginList',JSON.stringify(result))
            return result.code
        }else{
            return Promise.reject(new Error('reject'))
        }
    }
}
const getters={

}
export default {
    state,
    mutations,
    actions,
    getters
}